precision highp float;

#define NORMALIZED_POSITION

uniform vec2 u_screen_size;
uniform vec2 u_size;
uniform vec2 u_position;
uniform vec2 u_anchor;
uniform vec2 u_scale;
uniform float u_rotation;

attribute vec2 attPosition;
attribute vec2 attUV;

varying vec2 v_uv;
varying vec2 v_uv1;


vec2 transform (vec2 screen_size, vec2 image_size, vec2 translate, vec2 anchor, vec2 scale, float rotate, vec2 uv) {
    vec2 p = uv;
    p -= anchor;
    p *= image_size * scale;

    float R = rotate * 0.01745329251;
    float c = cos(R);
    float s = sin(R);
    p = mat2(c, s, -s, c) * p;

#ifdef NORMALIZED_POSITION
    p += translate * screen_size;
#else
    p += translate;
#endif
    p /= screen_size;
    return p;
}

void main () {
    v_uv = attUV;
    v_uv1 = transform(u_screen_size, u_size, u_position, u_anchor, u_scale, u_rotation, attUV);
    gl_Position = vec4(v_uv1 + v_uv1 - 1.0, 0.0, 1.0);
}
